package com.szbber.commen.dialog

import android.content.Context
import android.graphics.Color
import android.view.View
import android.widget.EditText
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter
import com.blankj.utilcode.utils.TimeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.contrarywind.view.WheelView
import com.orhanobut.logger.Logger
import com.szbber.commen.bean.*
import com.szbber.medical.commen.R
import top.defaults.colorpicker.ColorPickerView

/**
 * @author: Administrator
 * @date: 2022/4/19
 */
object DialogUtils {


    private var dialog: CustomDialog? = null
    private var dialogColor: CustomDialog? = null

    /**
     * 修改护理等级颜色
     */
    fun showNurseColorDialog(context: Context?, onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit){
       // hideDialog()
        var colorString = ""
        val view = View.inflate(context, R.layout.dialog_editnursecolor, null)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val colorPicker = view.findViewById<ColorPickerView>(R.id.colorPicker)
        colorPicker.subscribe { color, fromUser, shouldPropagate ->
            colorString = colorHex(color)
        }
        tvSure.setOnClickListener {
            onDialogClickBean(DialogClickBean(strValue = colorString))
            dialogColor?.dismiss()
        }
        tvCancel.setOnClickListener {
            dialogColor?.dismiss()
        }
        dialogColor = CustomDialog(context, view, R.style.MyDialogStyle)
        dialogColor?.setCancelable(true)
        dialogColor?.show()
    }

    private fun colorHex(color: Int): String {
        val a = Color.alpha(color)
        val r = Color.red(color)
        val g = Color.green(color)
        val b = Color.blue(color)
        return String.format("#%02X%02X%02X", r, g, b);
    }

    /**
     *   删除确认对话框
     */

    fun showDeleteDialog(context: Context?,onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit ){
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_delete, null)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        tvSure.setOnClickListener {
            onDialogClickBean(DialogClickBean())
            hideDialog()
        }
        tvCancel.setOnClickListener {
            hideDialog()
        }

        dialog = CustomDialog(context, view, R.style.MyDialogStyle)
        dialog?.setCancelable(false)
        dialog?.show()

    }

    /**
     * 添加护理等级标签
     */
    fun showAddCareLabel(context: Context?,onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit){
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_addcarelabel, null)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val etCareCat = view.findViewById<EditText>(R.id.etCareCat)
        val etCareName = view.findViewById<EditText>(R.id.etCareName)
        val tvFontColor = view.findViewById<TextView>(R.id.tvFontColor)
        val tvBgColor = view.findViewById<TextView>(R.id.tvBgColor)
        tvSure.setOnClickListener {
            val addCareLabelBean = AddCareLabelBean()
            addCareLabelBean.labelCat = etCareCat.text.toString()
            addCareLabelBean.labelName = etCareName.text.toString()
            addCareLabelBean.bgColor = tvBgColor.text.toString()
            addCareLabelBean.fontColor = tvFontColor.text.toString()
            onDialogClickBean(DialogClickBean(addCareLabelBean= addCareLabelBean))
            hideDialog()
        }
        tvCancel.setOnClickListener {
            hideDialog()
        }
        tvFontColor.setOnClickListener {
            showNurseColorDialog(context){
                tvFontColor.text = it.strValue
            }
        }
        tvBgColor.setOnClickListener {
            showNurseColorDialog(context){
                tvBgColor.text = it.strValue
            }
        }

        dialog = CustomDialog(context, view, R.style.MyDialogStyle)
        dialog?.setCancelable(false)
        dialog?.show()
    }

    /**
     * 查看推送消息
     */
    fun showMessageDialog(context: Context?, data: MessageListBean.Data) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_message, null)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        val tvContext = view.findViewById<TextView>(R.id.tvContext)
        val tvTime = view.findViewById<TextView>(R.id.tvTime)
        tvTitle.text = data.title
        tvContext.text = data.context
        tvTime.text = data.time
        tvSure.setOnClickListener {
            hideDialog()
        }
        tvCancel.setOnClickListener {
            hideDialog()
        }
        dialog = CustomDialog(context, view, R.style.MyDialogStyle)
        dialog?.setCancelable(false)
        dialog?.show()
    }

    /**
     * 添加推送消息
     */
    fun showAddMessage(context: Context?, onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_addmessage, null)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val etTile = view.findViewById<TextView>(R.id.etTile)
        val etContext = view.findViewById<TextView>(R.id.etContext)
        tvSure.setOnClickListener {
            val addMessageBean= AddMessageBean()
            addMessageBean.title = etTile.text.toString()
            addMessageBean.context = etContext.text.toString()
            onDialogClickBean(DialogClickBean(addmessageBean = addMessageBean))
            hideDialog()
        }
        tvCancel.setOnClickListener {
            hideDialog()
        }
        dialog = CustomDialog(context, view, R.style.MyDialogStyle)
        dialog?.setCancelable(true)
        dialog?.show()
    }

    /**
     * 修改护理等级名称
     */
    fun showNurseNameDialog(context: Context?, onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_editnursename, null)
        val etName = view.findViewById<EditText>(R.id.etName)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        tvSure.setOnClickListener {
            onDialogClickBean(DialogClickBean(strValue = etName.text.toString()))
            hideDialog()
        }
        tvCancel.setOnClickListener {
            hideDialog()
        }
        dialog = CustomDialog(context, view, R.style.MyDialogStyle)
        dialog?.setCancelable(true)
        dialog?.show()

    }

    /**
     * 选择病人
     */
    fun showPatientListBean(context: Context?, patientListBean: PatientListBean, onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit){
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        tvTitle.text ="选择病床"
        val adapter = object : BaseQuickAdapter<PatientListBean.Data, BaseViewHolder>(
            R.layout.item_check_device, patientListBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: PatientListBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.name+ "   "+ item.bed_code+"床")
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(patientListBean= patientListBean.data[position]))
            hideDialog()
        }
        tvCancel.setOnClickListener {
            hideDialog()
        }

        tvSure.setOnClickListener {
            hideDialog()
        }

        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()

    }



    /**
     * 选择护理标签
     */
    fun showCareListBean(context: Context?, careLevelListBean: CareLevelListBean, onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit){
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        tvTitle.text ="选择护理标签"
        val adapter = object : BaseQuickAdapter<CareLevelListBean.Data, BaseViewHolder>(
            R.layout.item_check_device, careLevelListBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: CareLevelListBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.label_name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(careLevelListBean= careLevelListBean.data[position]))
            hideDialog()
        }
        tvCancel.setOnClickListener {
            hideDialog()
        }

        tvSure.setOnClickListener {
            hideDialog()
        }

        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()

    }

    /**
     * 选择护理等级列表
     */
    fun showNurseLevelDialog(context: Context?, nurseLevelListBean: NurseLevelListBean,
        onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        tvTitle.text ="选择护理等级"
        val adapter = object : BaseQuickAdapter<NurseLevelListBean.Data, BaseViewHolder>(
            R.layout.item_check_device, nurseLevelListBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: NurseLevelListBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.level_name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(nurseLevel= nurseLevelListBean.data[position]))
            hideDialog()
        }
        tvCancel.setOnClickListener {
            hideDialog()
        }

        tvSure.setOnClickListener {
            hideDialog()
        }

        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()

    }


    /**
     * 选择床位 列表
     */
    fun showBedBeanDialog(context: Context?, bedBean: BedBean,
                           onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        tvCancel.setOnClickListener { hideDialog() }
        tvSure.setOnClickListener { hideDialog() }
        tvTitle.text ="选择床位"
        val adapter = object : BaseQuickAdapter<BedBean.Data, BaseViewHolder>(
            R.layout.item_check_device, bedBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: BedBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.bed_name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(bedBean= bedBean.data[position]))
            hideDialog()
        }
        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()

    }



    /**
     * 选择房间列表
     */
    fun showRoomBeanDialog(context: Context?, roomBean: RoomBean,
                           onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        tvCancel.setOnClickListener { hideDialog() }
        tvSure.setOnClickListener { hideDialog() }
        tvTitle.text ="选择房间"
        val adapter = object : BaseQuickAdapter<RoomBean.Data, BaseViewHolder>(
            R.layout.item_check_device, roomBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: RoomBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(roomBean= roomBean.data[position]))
            hideDialog()
        }
        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()

    }


    /**
     * 选择病区列表
     */
    fun showDistrictDialog(context: Context?, districtBean: DistrictBean,
                           onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        tvCancel.setOnClickListener { hideDialog() }
        tvSure.setOnClickListener { hideDialog() }
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        tvTitle.text ="选择病区"
        val adapter = object : BaseQuickAdapter<DistrictBean.Data, BaseViewHolder>(
            R.layout.item_check_device, districtBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: DistrictBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(districtBean= districtBean.data[position]))
            hideDialog()
        }
        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()

    }

    /**
     * 选择科室列表
     */
    fun showDeptBeanDialog(context: Context?, deptBean: DeptBean,
                               onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        tvTitle.text ="选择科室"
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val adapter = object : BaseQuickAdapter<DeptBean.Data, BaseViewHolder>(
            R.layout.item_check_device, deptBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: DeptBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(deptBean= deptBean.data[position]))
            hideDialog()
        }

        tvCancel.setOnClickListener {
            hideDialog()
        }

        tvSure.setOnClickListener {
            hideDialog()
        }

        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()
    }

    fun showCheckTimer(context: Context,onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit){
        hideDialog()

        val view = View.inflate(context, R.layout.dialog_checktimer, null)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val wheelView =view.findViewById<WheelView>(R.id.wheelview1)
        wheelView.setCyclic(false)
        wheelView.setDividerColor(context.resources.getColor(R.color.transparent))
        wheelView.setLineSpacingMultiplier(3.0f)
        wheelView.setItemsVisibleCount(2)
        wheelView.currentItem = 0
        val mOptionsItems = mutableListOf<String>()
        var year = "2020"
        for (index in 2020..2023){
            mOptionsItems.add("${index}年")
        }
        wheelView.setOnItemSelectedListener {
            year = mOptionsItems[it].subSequence(0,mOptionsItems[it].length-1).toString()
        }

        wheelView.adapter = ArrayWheelAdapter(mOptionsItems)
        val wheelView2 = view.findViewById<WheelView>(R.id.wheelview2)
        wheelView2.setCyclic(false)
        wheelView2.currentItem = 5
        wheelView2.setLineSpacingMultiplier(3.0f)
        wheelView2.setItemsVisibleCount(2)
        wheelView2.setDividerColor(context.resources.getColor(R.color.transparent))
        val mOptionsItems2 = mutableListOf<String>()
        for (index in 1..12) {
            if(index<10){
                mOptionsItems2.add( "0${index}月" )
            }else {
                mOptionsItems2.add("${index}月")
            }
        }
        var month = "06"
        wheelView2.setOnItemSelectedListener {
            month = mOptionsItems2[it].subSequence(0,mOptionsItems2[it].length-1).toString()
        }

        wheelView2.adapter = ArrayWheelAdapter(mOptionsItems2)
        val wheelView3 =view. findViewById<WheelView>(R.id.wheelview3);
        wheelView3.setCyclic(false)
        wheelView3.currentItem = 5
        wheelView3.setLineSpacingMultiplier(3.0f)
        wheelView3.setItemsVisibleCount(2)
        wheelView3.setDividerColor(context.resources.getColor(R.color.transparent))
        val mOptionsItems3 = mutableListOf<String>()
        for (index in 1..31) {
            if(index<10){
                mOptionsItems3.add("0${index}日");
            }else {
                mOptionsItems3.add( "${index}日");
            }
        }
        var day = "06"
        wheelView3.setOnItemSelectedListener {
            day = mOptionsItems3[it].subSequence(0,mOptionsItems3[it].length-1).toString()
        }
        tvSure.setOnClickListener {
            val str = "$year-$month-$day"
            onDialogClickBean(DialogClickBean(strValue = str))
            hideDialog()
        }

        wheelView3.adapter = ArrayWheelAdapter(mOptionsItems3)
        dialog = CustomDialog(context, view, R.style.MyDialogStyle)
        dialog?.setCancelable(false)
        dialog?.show()

    }

    /**
     * 选择护士列表
     */
    fun showNurseListDialog(context: Context?, nurseListBean: NurseListBean,
        onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        tvTitle.text ="选择护士"
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val adapter = object : BaseQuickAdapter<NurseListBean.Data, BaseViewHolder>(
            R.layout.item_check_device, nurseListBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: NurseListBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(nurseListBean= nurseListBean.data[position]))
            hideDialog()
        }

        tvCancel.setOnClickListener {
            hideDialog()
        }

        tvSure.setOnClickListener {
            hideDialog()
        }

        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()
    }


    /**
     * 选择医生列表
     */
    fun showDoctorListDialog(context: Context?, doctorListBean: DoctorListBean,
        onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        tvTitle.text ="选择医生"
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val adapter = object : BaseQuickAdapter<DoctorListBean.Data, BaseViewHolder>(
            R.layout.item_check_device, doctorListBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: DoctorListBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(doctorListBean= doctorListBean.data[position]))
            hideDialog()
        }

        tvCancel.setOnClickListener {
            hideDialog()
        }

        tvSure.setOnClickListener {
            hideDialog()
        }

        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()
    }

    /**
     * 选择医院列表
     */
    fun showHospitalInfoDialog(context: Context?, hospitalInfoBean: HospitalBean,
                               onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val tvTitle = view.findViewById<TextView>(R.id.tvTitle)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        tvCancel.setOnClickListener { hideDialog() }
        tvSure.setOnClickListener { hideDialog() }
        tvTitle.text ="选择医院"
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val adapter = object : BaseQuickAdapter<HospitalBean.Data, BaseViewHolder>(
            R.layout.item_check_device, hospitalInfoBean.data.toMutableList()
        ) {
            override fun convert(holder: BaseViewHolder, item: HospitalBean.Data) {
                holder.apply {
                    setText(R.id.tvName, item.name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(hospitalBean= hospitalInfoBean.data[position]))
            hideDialog()
        }
        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()
    }


    /**
     * 选择设备列表
     */
    fun showCheckDeviceDialog(context: Context?, onDialogClickBean: (dialogClickBean: DialogClickBean) -> Unit ) {
        hideDialog()
        val view = View.inflate(context, R.layout.dialog_checkdevice, null)
        val mRecyclerView = view.findViewById<RecyclerView>(R.id.mRecyclerView)
        val tvCancel = view.findViewById<TextView>(R.id.tvCancel)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        tvCancel.setOnClickListener { hideDialog() }
        tvSure.setOnClickListener { hideDialog() }

        val deviceList = mutableListOf< SettingItemBean>()
        deviceList.add(SettingItemBean(1, "床头屏设备"))
        deviceList.add(SettingItemBean(2, "门口屏设备"))
        deviceList.add(SettingItemBean(3, "走廊屏设备"))
        deviceList.add(SettingItemBean(4, "护士站大屏设备"))
        deviceList.add(SettingItemBean(5, "电话机设备"))
        val adapter = object : BaseQuickAdapter<SettingItemBean, BaseViewHolder>(
            R.layout.item_check_device,deviceList
        ) {
            override fun convert(holder: BaseViewHolder, item: SettingItemBean) {
                holder.apply {
                    setText(R.id.tvName, item.name)
                }
            }
        }
        mRecyclerView.adapter = adapter
        val manager = LinearLayoutManager(context)
        mRecyclerView.layoutManager = manager
        adapter.setOnItemClickListener { adapter, view, position ->
            onDialogClickBean(DialogClickBean(itemBean=deviceList[position]))
            hideDialog()
        }
        dialog = CustomDialog(context, view, R.style.MyDialogStyle, 1)
        dialog?.setCancelable(false)
        dialog?.show()
    }

    /**
     * 隐藏对话框
     */
    private fun hideDialog() {
        if (dialog != null && dialog?.isShowing!!) {
            dialog?.dismiss()
            dialog = null
        }
    }

}